|
|
|
|
|
|
|
perform database navigation. For example, suppose you want to allow the user to click an author's name in the list of authors to display the books by that author. You can do this very easily by generating hyperlinks for each author. To generate these hyperlinks, modify the While loop code from Listing 31.4 as follows: |
|
|
|
|
|
|
|
|
'DISPLAY THE RESULTS IN A TABLE
While Not rs.EOF
Response.Write ("<TR><TD><A HREF=author.asp?id=")
Response.Write rs.fields("AU_ID") & ">"
Response.Write rs.Fields("Author")
Response.Write ("</A><TD></TR>")
rs.MoveNext
Wend |
|
|
|
|
|
|
|
|
Run a search, and each author's name in the resulting list should appear as a hyperlink to a new ASP file, AUTHOR.ASP. If you choose View Source in your browser, you will see that each hyperlink is unique: |
|
|
|
|
|
|
|
|
<A HREF=author.asp?id=16061>Jackson, Bruce</A> |
|
|
|
|
|
|
|
|
The preceding line of HTML passes a parameter id to the ASP page AUTHOR.ASP. If you click the hyperlink, the browser will ask the server for this URL: |
|
|
|
|
|
|
|
|
http://bshome/test/author.asp?id=16061 |
|
|
|
|
|
|
|
|
Note that the URL includes the id parameter, which is separated from the base (or target) URL by a question mark. If there were additional parameters, they would be separated by an ampersand (&). The syntax for using parameters in a URL is as follows: |
|
|
|
|
|
|
|
|
http://targetURL ? parm1name=parm1value & parm2name=parm2value & parm3name=parm3value etc . . . |
|
|
|
|
|
|
|
|
The collection of parameters in an URL is also known as the query string and can be retrieved with the QueryString collection of the Request object: |
|
|
|
|
|
|
|
|
If Request.QueryString("id") = "" Then Response.Write "No ID entered!" |
|
|
|
|
|
|
|
|
As with the Request.Form example in Listing 31.4, the value passed to an ASP page in the query string can be retrieved and used in a database query: |
|
|
|
|
|
|
|
|
sSQL = "SELECT Title FROM [Title Author], [Titles] "
sSQL = sSQL & " WHERE [Title Author].ISBN = [Titles].ISBN "
sSQL = sSQL & " and [Title Author].AU_ID=" & Request.QueryString("id") |
|
|
|
|
|
|
|
|
As an exercise, create AUTHOR.ASP using the preceding query. Except for the database field names, the structure of the ASP file should be identical to that in Listing 31.4. |
|
|
|
|
|
|
|
|
Updating Information in a Database |
|
|
|
|
|
|
|
|
Displaying data with ASP is useful, but at some point you also need to add or edit information. The previous section described two ways to get input from a client's browser to an ASP page: |
|
|
|
|
|
|
|
|
Adding parameters to the URL querystring |
|
|
|
|
|